local assets=
{
}

local function onequip(inst, owner) 
    owner.components.inventory:SetOverflow(inst)
    inst.components.container:Open(owner)
    
end

local function onunequip(inst, owner) 
    owner.components.inventory:SetOverflow(nil)
    inst.components.container:Close(owner)
end


local slotpos = {}

for y = 0, 3 do
	table.insert(slotpos, Vector3(-162, -y*75 + 114 ,0))
	table.insert(slotpos, Vector3(-162 +75, -y*75 + 114 ,0))
end

local function SetPlayer(inst, player)
    inst.player = player
    if player ~= nil then
        inst.components.container:Open(player)
        player.components.inventory:SetOverflow(inst)
    else
        inst.components.container:Close()
        if inst.player then
            inst.player.components.inventory:SetOverflow(nil)
        end
    end
end

local function fn(Sim)
	local inst = CreateEntity()
    
	inst.entity:AddTransform()
        
    -- inst.components.equippable:SetOnEquip( onequip )
    -- inst.components.equippable:SetOnUnequip( onunequip )
    
    
    inst:AddComponent("container")
    inst.components.container:SetNumSlots(#slotpos)
    inst.components.container.widgetslotpos = slotpos
    inst.components.container.widgetanimbank = "ui_backpack_2x4"
    inst.components.container.widgetanimbuild = "ui_backpack_2x4"
    inst.components.container.widgetpos = Vector3(-5,-50,0)
    inst.components.container.side_widget = true
    inst.components.container.type = "rg_pack" 
    
    inst.SetPlayer = SetPlayer

    return inst
end

local function start_inv_fn()
    local inst = SpawnPrefab("rg_backpack")
    
    return inst
end

return Prefab("rg_backpack", fn, assets), Prefab("rg_backpack_start_inv", start_inv_fn)
